﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Transaction.Interceptor;
using OpenSda.Agilcont.Common.Data.Entities;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Business.Exceptions;
using OpenSda.Agilcont.Common.Business.Contracts;

namespace OpenSda.Agilcont.Common.Business.SfContexts
    
{

    public class ModuleAccessBusiness : IModuleAccessBusiness
    {
        IModuleAccessData moduleAccessData;
        IUserData userData;
        public IModuleAccessData ModuleAccessData { set { moduleAccessData = value; } }
        public IUserData UserData { set { userData = value; } }

        public ModuleAccessBusiness()
        {
            
        }
        [Transaction]
        public ModuleAccess Save(ModuleAccess moduleAccess)
        {
            if (moduleAccess == null) //|| empresa.Identity == Guid.Empty
                throw new ModuleAccessCannotBeNullException();
            // Não permitir duplicar Codigo
            if (moduleAccessData.GetAllQueryable().Where(ms => ms.Module != moduleAccess.Module && ms.CreationDate == moduleAccess.CreationDate).Count() > 0)
                throw new ModuleAccessCodeInUseException();

            // Não permitir duplicar RazonSocial
            if (moduleAccessData.GetAllQueryable().Where(ms => ms.Module != moduleAccess.Module).Count() > 0)
                throw new ModuleAccessNameInUseException();

            return moduleAccessData.Save(moduleAccess);


 	       
        }

        public ModuleAccess  Delete(ModuleAccess moduleAccess)
        {
 	        throw new NotImplementedException();
        }

        public ModuleAccess  GetById(object id)
        {
 	        throw new NotImplementedException();
        }

        public ModuleAccess  GetListByFilter(string filter)
        {
 	        throw new NotImplementedException();
        }
    }
}
